package com.jr.service.impl;


import com.jr.entity.User;
import com.jr.mapper.UserDao;
import com.jr.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;


/**
 * 用户信息表
 *
 * @author Snoopy
 * @since 1.0.0 2022-12-31
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;


    /**
     * @description: service层登录验证
     * @author: 金宏飞
     * @date: 2023/1/3 11:52
     * @param: [user]
     * @return: boolean
     **/
    @Override
    public boolean loginUser(User user, HttpSession session) {
        User user1 =  userDao.selectUser(user);
        session.setAttribute("user",user1);
        return user1 == null;
    }

    /**
     * @description: Service层账户查重
     * @author: 金宏飞
     * @date: 2023/1/5 9:33
     * @param: [user]
     * @return: boolean
     **/
    @Override
    public boolean accountReview(User user) {
        return userDao.selectAccount(user)!=null?true:false;
    }
    @Override
    public boolean registerUser(User user) {
        return userDao.insertUser(user) == 1;
    }

    /**
     * @description： 根据id查询全部信息
     * @author: 王子华
     * @date: 2023/1/3 10:12
     * @param: [user]
     * @return: com.jr.entity.User
     **/

    @Override
    public User getUserByUid(User user) {
        return userDao.selectUser(user);
    }

    /**
     * @description:更新数据
     * @author: 王子华
     * @date: 2023/1/6 11:26
     * @param: [user]
     * @return: int
     **/
    @Override
    public int updateUserinfoByUid(User user) {
        return userDao.updateUser(user);
    }

    /**
     * @description: 修改密码
     * @author: 金宏飞
     * @date: 2023/1/10 14:38
     * @param: [user]
     * @return: boolean
     **/
    @Override
    public boolean changeUserInfo(User user) {
        return userDao.updateUpassword(user) == 1;
    }

    /**
     * @description: 为修改密码来查询用户信息
     * @author: 金宏飞
     * @date: 2023/1/10 14:57
     * @param:
     * @return:
     **/
    @Override
    public User queryUser(User user) {
        return userDao.searchUserpassword(user);
    }

}